package com.example.demo.controller;

import com.example.demo.Service.IProductDetailService;
import com.example.demo.entity.vo.ProductDetailVo;
import com.example.demo.util.JWTUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/product")
@CrossOrigin(origins = "*")
public class ProductDetailController {
    @Autowired
    private IProductDetailService productDetailService;

    @GetMapping("/detail/{productId}")
    public Map<String,Object> detail(@PathVariable Long productId, HttpServletRequest request){

        ProductDetailVo productDetailVo = productDetailService.vo(productId);

        productDetailVo.setIsCollect(productDetailService.count(JWTUtil.getUserId(request.getHeader("Authorization")),productId));

        Map<String,Object> map = new HashMap<>();

        map.put("data",productDetailVo);
        map.put("code",200);
        map.put("msg","查询成功");


        return map;

    }
}
